<template>
  <div class="home">
    <!-- 轮播图 -->
    <van-search
      v-model="seacrvalue"
      placeholder="请输入搜索关键词"
      disabled
      shape="round"
      @click="$router.push('/hoem/searchPopup')"
    />
    <van-swipe class="my-swipe" :autoplay="3000">
      <van-swipe-item v-for="item in berner" :key="item.id">
        <img :src="item.image_url" alt="#" width="100%" />
      </van-swipe-item>
    </van-swipe>
    <!-- channel 宫格 -->
    <van-grid>
      <van-grid-item
        v-for="(item, index) in channel"
        :key="index"
        :icon="item.icon_url"
        :text="item.name"
      />
    </van-grid>
    <!-- 品牌制造直供 -->
    <div>
      <div class="ppzzszg"><h3>品牌制造商直供</h3></div>
      <ul class="brandListBox">
        <li v-for="item in brandList" :key="item.id">
          <img :src="item.pic_url" alt="" />
          <h4>{{ item.name }}</h4>
          <p>￥{{ item.floor_price }}元</p>
        </li>
      </ul>
    </div>
    <!-- 新品首发 -->
    <div>
      <div class="ppzzszg"><h3>周一周四.新品首发</h3></div>
      <ul class="newGoodsListBox">
        <li v-for="item in newGoodsList" :key="item.id">
          <img :src="item.list_pic_url" alt="" />
          <h4>{{ item.name }}</h4>
          <p>￥{{ item.retail_price }}元</p>
        </li>
      </ul>
    </div>
    <!-- 人气推荐 -->
    <div>
      <div class="ppzzszg"><h3>人气推荐</h3></div>
    </div>
    <ul class="hotGoodsListBox">
      <li v-for="item in hotGoodsList" :key="item.id">
        <a href="#" class="hotGoodsListBox-1">
          <img :src="item.list_pic_url" alt="#" />
        </a>
        <div class="hotGoodsListBox-2">
          <h3>{{ item.name }}</h3>
          <p>{{ item.goods_brief }}</p>
          <p>￥{{ item.retail_price }}元</p>
        </div>
      </li>
    </ul>
    <!-- 专题精选 -->
    <div>
      <div class="ppzzszg"><h3>专题精选</h3></div>
    </div>
    <van-swipe @change="onChange" class="topicListBox">
      <van-swipe-item v-for="item in topicList" :key="item.id">
        <img :src="item.scene_pic_url" alt="" />
        <h3>{{ item.title }}</h3>
        <span>￥{{ item.price_info }}元起</span>
        <p>{{ item.subtitle }}</p>
      </van-swipe-item>
      <template #indicator>
        <div class="custom-indicator"></div>
      </template>
    </van-swipe>

    <!-- 后面的内容 -->
    <div v-for="item in categoryList" :key="item.id">
      <div class="ppzzszg">
        <h3>{{ item.name }}</h3>
      </div>
      <div class="categoryListBox">
        <ul v-for="item in item.goodsList" :key="item.id">
          <li>
            <img :src="item.list_pic_url" alt="" />
            <h4>{{ item.name }}</h4>
            <p>￥{{ item.retail_price }}元</p>
          </li>
        </ul>
      </div>
    </div>

    <router-view></router-view>
  </div>
</template>

<script>
//请求数据 的导入
import { GetHomeData } from "../../request/api";

export default {
  name: "Home",
  data() {
    return {
      seacrvalue: "",
      berner: [],
      channel: [],
      brandList: [],
      newGoodsList: [],
      hotGoodsList: [],
      topicList: [],
      categoryList: [],
    };
  },
  created() {
    GetHomeData().then((res) => {
      console.log(res.data);
      let {
        banner,
        channel,
        brandList,
        newGoodsList,
        hotGoodsList,
        topicList,
        categoryList,
      } = res.data;
      (this.berner = banner),
        (this.channel = channel),
        (this.brandList = brandList),
        (this.newGoodsList = newGoodsList);
      this.hotGoodsList = hotGoodsList;
      this.topicList = topicList;
      this.categoryList = categoryList;
    });
  },
  components: {},
  methods: {
    onChange(index) {
      this.current = index;
    },
  },
};
</script>
<style lang="less">
//轮播图
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  text-align: center;
}
//channel 宫格
.van-grid-item {
  flex-basis: 20% !important;
}
//品牌制造直供
.ppzzszg {
  line-height: 50px;
  text-align: center;
  background-color: #fff;
  margin-top: 20px;
}
.brandListBox {
  height: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  background-color: #fff;
  li {
    width: 49%;
    height: 100%;
    position: relative;
    margin-bottom: 5px;
    img {
      width: 100%;
    }
    p {
      position: absolute;
      top: 50px;
      left: 10px;
      font-size: 14px;
    }
    h4 {
      position: absolute;
      top: 20px;
      left: 10px;
      font-size: 14px;
    }
  }
}
//新品首发
.newGoodsListBox {
  height: 100%;
  display: flex;
  flex-wrap: wrap;
  // justify-content: space-between;
  background-color: #fff;
  li {
    width: 50%;
    height: 100%;
    position: relative;
    // margin-bottom: 5px;
    img {
      width: 100%;
    }
    p,
    h4 {
      font-size: 14px;
      text-align: center;
      line-height: 20px;
    }
  }
}
//人气推荐
.hotGoodsListBox {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  .hotGoodsListBox-1 {
    width: 88px;
    height: 88px;
    display: inline-block;
    img {
      width: 100%;
    }
  }
  .hotGoodsListBox-2 {
    display: inline-block;
    line-height: 25px;
    font-size: 14px;
  }
}
//专题精选
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  display: block;
  text-align: center;
}
.topicListBox {
  width: 100%;
  img {
    width: 100%;
    height: 200px;
  }
}
//下面
.categoryListBox {
  height: 100%;
  display: flex;
  flex-wrap: wrap;
  background-color: #fff;
  ul {
    width: 50%;
    height: 100%;
    text-align: center;
    li {
      width: 100%;
      height: 100%;
      position: relative;
      img {
        width: 100%;
      }
      p,
      h4 {
        font-size: 14px;
        text-align: center;
        line-height: 20px;
      }
    }
  }
}
</style>

